import React, { useEffect } from 'react'
import axios from 'axios'
import { useHistory } from "react-router-dom";
import { Form, Input, Button, Checkbox } from 'antd';
import './style/Frist_one.css'

const Frist_one = () => {

    let data = '';
    let history = useHistory();

    // 提交表单且数据验证成功后回调事件
    const onFinish = (values: any) => {
        if (data.userName === values.username && data.passWord === values.password) {
            history.push("/frist_three")
        }else {
            alert('数据或密码错误，请重新输入')
        }
    };

    const onFinishFailed = (errorInfo: any) => {
        console.log('Faile11d:', errorInfo);
    };



    useEffect(() => {
        axios.get('http://localhost:9000/data.json').then((datas) => {
            data = datas.data.users
            // console.log('获取数据',data)
        })
    })


    return (
        <div className='From_css'>
            <Form
                name="basic"
                labelCol={{ span: 8 }}
                wrapperCol={{ span: 16 }}
                initialValues={{ remember: true }}
                onFinish={onFinish}
                onFinishFailed={onFinishFailed}
                autoComplete="off"
            >
                <Form.Item
                    label="Username"
                    name="username"
                    rules={[{ required: true, message: 'Please input your username!' }]}
                >
                    <Input />
                </Form.Item>

                <Form.Item
                    label="Password"
                    name="password"
                    rules={[{ required: true, message: 'Please input your password!' }]}
                >
                    <Input.Password />
                </Form.Item>

                <Form.Item name="remember" valuePropName="checked" wrapperCol={{ offset: 8, span: 16 }}>
                    <Checkbox>Remember me</Checkbox>
                </Form.Item>

                <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
                    <Button type="primary" htmlType="submit">
                        Submit
                    </Button>
                </Form.Item>
            </Form>
        </div>
    );
};

export default Frist_one;